<template>
	<view class="container">
		<u--form :model="form" :rules="rules" ref="uForm" labelWidth="90">
			<u-form-item label="回访客户" prop="nickname" borderBottom @click="show = true" ref="item1">
				<u--input v-model="form.nickname" disabled disabledColor="#ffffff" placeholder="请选择回访客户" suffixIcon="arrow-down"></u--input>
			</u-form-item>
			<u-form-item label="回访内容" prop="content" borderBottom ref="item1">
				<u--textarea v-model="form.content" placeholder="请输入回访内容" count ></u--textarea>
			</u-form-item>
		</u--form>
		<u-button type="success" @click="submit" color="#19BC9C" :customStyle="btnStyle">提交</u-button>
		<u-picker :show="show" :columns="buslist" keyName="nickname" @cancel="show = false" @confirm="confirm"></u-picker>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				rules: {
					'content': {
						type: 'string',
						required: true,
						message: '请填写回访内容',
						trigger: ['blur', 'change']
					},
					'nickname': {
						type: 'string',
						required: true,
						message: '请选择回访客户',
						trigger: ['blur', 'change']
					},
				},
				form: {
					nickname: '',
					busid: '',
					adminid: '',
					content:''
				},
				btnStyle: {
					width: '100%',
					marginTop: '10px'
				},
				show: false,
				buslist: [],
				btnStyle: {
					width: '100%',
					marginTop: '10px'
				},
				LoginUser: {},
			}
		},
		onReady() {
			this.$u.auth.check();
			this.LoginUser = uni.getStorageSync('LoginUser') ? uni.getStorageSync('LoginUser') : {}
			this.form.adminid=this.LoginUser.id
			//onReady 为uni-app支持的生命周期之一
			this.$refs.uForm.setRules(this.rules)
			this.getBusData()
		},
		methods: {
			submit() {
				this.$refs.uForm.validate().then(async () => {
					let result = await this.$u.api.manage.vistAdd({
						busid: this.form.busid,
						adminid: this.form.adminid,
						content: this.form.content
					})
					if (result.code == 1) {
						this.$refs.uToast.show({
							type: 'success',
							message: result.msg,
							complete: function() {
								uni.navigateTo({
									url: '/pages/manage/visit/index'
								});
							}
						})
					} else {
						this.$refs.uToast.show({
							type: 'error',
							message: result.msg
						})
					}
				}).catch(errors => {})
			},
			async getBusData(){
				let result = await this.$u.api.manage.vistBusiness({adminid:this.LoginUser.id})
				if (result.code == 1) {
					this.buslist.push(result.data)
				}
			},
			confirm(val){
				this.show = false
				this.form.nickname = val.value[0].nickname
				this.form.busid = val.value[0].id
			}
		},
	}
</script>

<style>
	.container {
		padding: 8px;
	}
</style>